package wahadlo.math;

/**
 * Klasa reprezentuje funkcję prędkości od czasu dla wahadła matematycznego.<br/>
 * v(t)=x'(t)=-A<sub>0</sub>&beta;e<sup>-&beta;t</sup>cos(&omega;t + &phi;)+
 * -A<sub>0</sub>&omega;e<sup>-&beta;t</sup>sin(&omega;t + &phi;)
 * 
 * @author Koziołek
 * 
 */
public class Speed implements Function {

	private Double a0;
	private Double beta;
	private Double length;

	public Speed(Double a0, Double beta, Double length) {
		this.a0 = a0;
		this.beta = beta;
		this.length = length;
	}

	public Double getValue(Double... points) {
		Double t;
		if (points != null && points.length > 0) {
			t = points[0];
		} else {
			throw new NullPointerException();
		}

		Double firstA0Part = a0 * -beta * Math.pow(Math.E, (-beta * t));
		Double firstCosPart = Math.cos((2 * Math.PI / Math.sqrt(length
				/ Function.G))
				* t);

		Double firstPart = firstA0Part * firstCosPart;

		Double secondA0Part = a0 * Math.sqrt(length / Function.G)
				* Math.pow(Math.E, (-beta * t));
		Double secondCosPart = 2 * Math.PI
				* Math.sin((2 * Math.PI / Math.sqrt(length / Function.G)) * t);

		Double secondPart = secondA0Part * secondCosPart;

		return firstPart + secondPart;
	}

}
